# -------------------------------------------------------------------------
# Doxygen documentation batch
# modified by S. Barre (Time-stamp: <2005-12-05 12:58:52 barre>
# -------------------------------------------------------------------------

# Path to several tools (_PROG to avoid the typical GZIP env var pb)
# Example: 
#   DOXYGEN_PROG=@DOXYGEN@        (INCLUDE(FindDoxygen.cmake))
#   GZIP_PROG=@GZIP@              (INCLUDE(FindCygwin.cmake))
#   HHC_PROG=@HTML_HELP_COMPILER@ (INCLUDE(FindHTMLHelp.cmake))
#   MV_PROG=@MV@                  (INCLUDE(FindCygwin.cmake))
#   PERL_PROG=@PERL@              (INCLUDE(FindPerl.cmake))
#   RM_PROG=@RM@                  (INCLUDE(FindCygwin.cmake))
#   TAR_PROG=@TAR@                (INCLUDE(FindCygwin.cmake))
#   WGET_PROG=@WGET@              (INCLUDE(FindWget.cmake))
#
export DOXYGEN_PROG="@DOXYGEN@"        # Doxygen
export GZIP_PROG="@GZIP@"              # gzip (Unix-like 'gzip compressor')
export GNUPLOT_PROG="@GNUPLOT@"        # gnuplot (data plotting program)
export HHC_PROG="@HTML_HELP_COMPILER@" # HTML Help Compiler
export MV_PROG="@MV@"                  # mv (Unix-like 'move/rename files')
export PERL_PROG="@PERL@"              # Perl
export RM_PROG="@RM@"                  # rm (Unix-like 'remove files')
export TAR_PROG="@TAR@"                # tar (Unix-like 'archiver')
export WGET_PROG="@WGET@"              # wget (remote file retrieval)

# PROJECT_NAME:
# Documentation/project name. Used in some of the resulting file names and
# xrefs to uniquify two or more projects linked together through their 
# Doxygen's tag files. Mandatory for each documentation set.
# Note: might be the same as the doxyfile's PROJECT_NAME
# Example: 
#   PROJECT_NAME=VTK
#
export PROJECT_NAME=VTK

# PATH_TO_VTK_DOX_SCRIPTS:
# Path to the directory holding the Perl scripts used to produce the VTK doc
# in Doxygen format. You need the VTK source files or a local copy of 
# these scripts.
# Example: 
#   PATH_TO_VTK_DOX_SCRIPTS=@VTK_SOURCE_DIR@/Utilities/Doxygen
#
export PATH_TO_VTK_DOX_SCRIPTS="@VTK_SOURCE_DIR@/Utilities/Doxygen"

# SOURCE_DIR:
# Source directory. The top directory of the source files.
# Example: 
#   SOURCE_DIR=@VTK_SOURCE_DIR@
#
export SOURCE_DIR="@VTK_SOURCE_DIR@"

# REL_PATH_TO_TOP:
# Relative path from the top directory of the source files to the directory
# (or top directory) holding the files to document. Useful if several parts
# of the same source directory should be documented separately.
# Example: 
#   REL_PATH_TO_TOP=.
#   REL_PATH_TO_TOP=framework/src
#
export REL_PATH_TO_TOP=.

# INTERMEDIATE_DOX_DIR:
# Directory where the intermediate Doxygen files should be stored (mainly
# these headers files converted from the VTK format to the Doxygen format).
# This directory is erased at the end of this script, unless you comment
# the corresponding line.
# DOXTEMP might be used to simplify the syntax.
# Example: 
#   DOXTEMP=DOXTEMP=@VTK_BINARY_DIR@/Utilities/Doxygen
#   INTERMEDIATE_DOX_DIR=$DOXTEMP/dox
#
export DOXTEMP="@VTK_BINARY_DIR@/Utilities/Doxygen"
export INTERMEDIATE_DOX_DIR="$DOXTEMP/dox"

# DATA_ROOT:
# Data directory. The root directory of the data files.
# Example: 
#   DATA_ROOT=@VTK_DATA_ROOT@
#
export DATA_ROOT="@VTK_DATA_ROOT@"

# CVSWEB, CVSWEB_SUFFIX, CVSWEB__CHECKOUT, 
# CVSWEB_DATA, CVSWEB_DATA_SUFFIX, CVSWEB_DATA_CHECKOUT:
# URL to the CVSWeb of the project + same in checkout mode (i.e. appending a 
# file  name to this URL will retrieve the contents of the file). In the same way
# CVSWEB_SUFFIX will be appended to the result. 
# Same applies to CVSWEB_DATA, which is the URL to the CVSWeb
# of the Data's project.
# Example: 
#   CVSWEB=http://public.kitware.com/cgi-bin/cvsweb.cgi/VTK
#   CVSWEB_SUFFIX=?cvsroot=VTK
#   CVSWEB_CHECKOUT=http://public.kitware.com/cgi-bin/cvsweb.cgi/~checkout~/VTK
#   CVSWEB_DATA=http://public.kitware.com/cgi-bin/cvsweb.cgi/VTKData
#   CVSWEB_DATA_SUFFIX=?cvsroot=VTK
#   CVSWEB_DATA_CHECKOUT=http://public.kitware.com/cgi-bin/cvsweb.cgi/~checkout~/VTKData
#
export CVSWEB=http://public.kitware.com/cgi-bin/viewcvs.cgi
export CVSWEB_SUFFIX=?root=VTK
export CVSWEB_CHECKOUT=http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*
export CVSWEB_DATA=http://public.kitware.com/cgi-bin/viewcvs.cgi
export CVSWEB_DATA_SUFFIX=?root=VTKData
export CVSWEB_DATA_CHECKOUT=http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*

# DOXYFILE:
# Path to the Doxygen configuration file (i.e. doxyfile).
# Example: 
#   DOXYFILE=$DOXTEMP/doxyfile
#
export DOXYFILE="$DOXTEMP/doxyfile"

# OUTPUT_DIRECTORY ALLOW_ERASE_OUTPUT_DIRECTORY:
# Path to the Doxygen output directory (where the resulting doc is stored).
# Note: should be the same as your doxyfile's OUTPUT_DIRECTORY
# If ON, allows the output directory to be erased when some advanced output
# file have been produced (HTML Help, or TAR archive for example).
# Example: 
#   OUTPUT_DIRECTORY=$DOXTEMP/doc
#   ALLOW_ERASE_OUTPUT_DIRECTORY=ON
#
export OUTPUT_DIRECTORY="$DOXTEMP/doc"
export ALLOW_ERASE_OUTPUT_DIRECTORY=ON

# COMPILE_HTML_HELP RESULTING_HTML_HELP_FILE:
# Compile the CHM (Compressed HTML) HTML Help file, name of the resulting 
# file. If set to ON and name is non-empty these options will actually 
# trigger the HTML-Help compiler to create the CHM. The resulting
# file (usually index.chm) will be renamed to this name.
# Note: if ON, the whole $OUTPUT_DIRECTORY will be erased at the end of
#       this script, since this file is considered to be one of the 
#       advanced final output, unless ALLOW_ERASE_OUTPUT_DIRECTORY is OFF
# Note: your doxyfile should be configured to enable HTML Help creation 
#       (using GENERATE_HTML = YES, GENERATE_HTMLHELP = YES)
# Example: 
#   COMPILE_HTML_HELP=ON
#   COMPILE_HTML_HELP=@DOCUMENTATION_HTML_HELP@
#   RESULTING_HTML_HELP_FILE=$DOXTEMP/vtk@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@.chm
#
export COMPILE_HTML_HELP=@DOCUMENTATION_HTML_HELP@
export RESULTING_HTML_HELP_FILE="$DOXTEMP/vtk@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@.chm"

# CREATE_HTML_TARZ_ARCHIVE RESULTING_HTML_TARZ_ARCHIVE_FILE:
# Create a compressed (gzip) tar archive of the html directory (located
# under the OUTPUT_DIRECTORY), and name of the resulting archive file. 
# Note: your doxyfile should be configured to enable HTML creation 
#       (using GENERATE_HTML = YES)
# Example: 
#   CREATE_HTML_TARZ_ARCHIVE=ON
#   CREATE_HTML_TARZ_ARCHIVE=@DOCUMENTATION_HTML_TARZ@
#   RESULTING_HTML_TARZ_ARCHIVE_FILE=$DOXTEMP/vtk@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@-html.tar.gz
#
export CREATE_HTML_TARZ_ARCHIVE=@DOCUMENTATION_HTML_TARZ@
export RESULTING_HTML_TARZ_ARCHIVE_FILE="$DOXTEMP/vtk@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@-html.tar.gz"

# DOWNLOAD_VTK_TAGFILE VTK_TAGFILE VTK_TAGFILE_REMOTE_DIR VTK_TAGFILE_DEST_DIR:
# Download the VTK tag file, name, remote location and destination dir of this
# tag file. If set to ON, the tag file is retrieved from its remote location
# using wget and stored in the destination dir. It will be automatically 
# deleted at the end of this script.
# Note: your doxyfile must be tailored to make use-of or create this tag file.
#    (using TAGFILES = vtk@VTK_MAJOR_VERSION@-nightly.tag=http://www.vtk.org/doc/nightly/html
#        or GENERATE_TAGFILE = "@VTK_BINARY_DIR@/Utilities/Doxygen/vtk@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@.tag")
# Example: 
#   DOWNLOAD_VTK_TAGFILE=OFF
#   VTK_TAGFILE=vtk@VTK_MAJOR_VERSION@-nightly.tag
#   VTK_TAGFILE_REMOTE_DIR=http://www.vtk.org/doc/nightly/html
#   VTK_TAGFILE_DEST_DIR=$DOXTEMP
#
export DOWNLOAD_VTK_TAGFILE=OFF
export VTK_TAGFILE=vtk@VTK_MAJOR_VERSION@-nightly.tag
export VTK_TAGFILE_REMOTE_DIR=http://www.vtk.org/doc/nightly
export VTK_TAGFILE_DEST_DIR="$DOXTEMP"

# ----------------------------------------------------------------------------
# Convert the VTK headers to the Doxygen format.

if test "x$PERL_PROG" != "xNOTFOUND" ; then
    "$PERL_PROG" "$PATH_TO_VTK_DOX_SCRIPTS/doc_header2doxygen.pl" \
        --to "$INTERMEDIATE_DOX_DIR" \
        --relativeto "$SOURCE_DIR/$REL_PATH_TO_TOP" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Charts" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Chemistry" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Common" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Filtering" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/GenericFiltering" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/GenericFiltering/Testing/Cxx" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Geovis" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Graphics" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/GUISupport/MFC" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/GUISupport/Qt" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Hybrid" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Imaging" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Infovis" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/IO" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Parallel" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Rendering" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/TextAnalysis" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Views" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/VolumeRendering" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Widgets"
fi

# ----------------------------------------------------------------------------
# Build the Events invocation list.

if test "x$PERL_PROG" != "xNOTFOUND" ; then
    "$PERL_PROG" "$PATH_TO_VTK_DOX_SCRIPTS/doc_codematch.pl" \
        --codematch "\w(?:->|\.)InvokeEvent\s*\(\s*(vtkCommand::\w+)[\s,]" \
        --label "Events" \
        --project "$PROJECT_NAME" \
        --sectionmatch "^vtkCommand::(\w)" \
        --store "doc_""$PROJECT_NAME""_events.dox" \
        --title "Event to Classes" \
        --sectionmatch2 "^vtk(\w)" \
        --store2 "doc_""$PROJECT_NAME""_events2.dox" \
        --title2 "Class to Events" \
        --to "$INTERMEDIATE_DOX_DIR" \
        --unique "v" \
        --relativeto "$SOURCE_DIR/$REL_PATH_TO_TOP" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Charts" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Chemistry" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Common" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Filtering" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/GenericFiltering" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/GenericFiltering/Testing/Cxx" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Geovis" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Graphics" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/GUISupport/MFC" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/GUISupport/Qt" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Hybrid" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Imaging" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Infovis" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/IO" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Parallel" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Widgets" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Rendering" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Views" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/VolumeRendering"
fi

# ----------------------------------------------------------------------------
# Build the full-text index.

if test "x$PERL_PROG" != "xNOTFOUND" ; then
    "$PERL_PROG" "$PATH_TO_VTK_DOX_SCRIPTS/doc_index.pl" \
        --project "$PROJECT_NAME" \
        --stop  "$PATH_TO_VTK_DOX_SCRIPTS/doc_index.stop" \
        --store "doc_""$PROJECT_NAME""_index.dox" \
        --to "$INTERMEDIATE_DOX_DIR" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Charts" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Chemistry" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Common" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Filtering" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/GenericFiltering" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/GenericFiltering/Testing/Cxx" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Geovis" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Graphics" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/GUISupport/MFC" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/GUISupport/Qt" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Hybrid" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Imaging" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Infovis" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/IO" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Parallel" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Widgets" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Rendering" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/Views" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP/VolumeRendering"
fi

# ----------------------------------------------------------------------------
# Extract the VTK version and create the main page.

if test "x$PERL_PROG" != "xNOTFOUND" ; then
    "$PERL_PROG" "$PATH_TO_VTK_DOX_SCRIPTS/doc_version.pl" \
        --version_file "$SOURCE_DIR/$REL_PATH_TO_TOP/CMakeLists.txt" \
        --revision_file "@VTK_BINARY_DIR@/Utilities/vtksys/DateStamp.h" \
        --logo "$PATH_TO_VTK_DOX_SCRIPTS/vtk-logo.gif" \
        --store "doc_""$PROJECT_NAME""_version.dox" \
        --to "$INTERMEDIATE_DOX_DIR"
fi

# ----------------------------------------------------------------------------
# Generate the 'Class to Examples' page cross-linking each class to these
# examples that use that class.

if test "x$PERL_PROG" != "xNOTFOUND" ; then
    "$PERL_PROG" "$PATH_TO_VTK_DOX_SCRIPTS/doc_class2example.pl" \
        --baselinedir "$DATA_ROOT/Baseline" \
        --baselineicon "pic.gif" \
        --baselinelink "$CVSWEB_DATA_CHECKOUT/Baseline" \
        --baselinelinksuffix "$CVSWEB_DATA_SUFFIX" \
        --datamatch "\W(VTK_DATA_ROOT|VTKData|(vtk)?GetDataRoot|ExpandDataFileName)\W" \
        --dataicon "paper-clip.gif" \
        --dirmatch "^Examples\$" \
        --label "Examples" \
        --link "$CVSWEB_CHECKOUT" \
        --linksuffix "$CVSWEB_SUFFIX" \
        --project "$PROJECT_NAME" \
        --store "doc_""$PROJECT_NAME""_class2examples.dox" \
        --title "Class To Examples" \
        --to "$INTERMEDIATE_DOX_DIR" \
        --unique "e" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP"
fi

# ----------------------------------------------------------------------------
# Generate the 'Class to Tests' page cross-linking each class to these
# tests that use that class.

if test "x$PERL_PROG" != "xNOTFOUND" ; then
    "$PERL_PROG" "$PATH_TO_VTK_DOX_SCRIPTS/doc_class2example.pl" \
        --baselinedir "$DATA_ROOT/Baseline" \
        --baselineicon "pic.gif" \
        --baselinelink "$CVSWEB_DATA_CHECKOUT/Baseline" \
        --baselinelinksuffix "$CVSWEB_DATA_SUFFIX" \
        --datamatch "\W(VTK_DATA_ROOT|VTKData|(vtk)?GetDataRoot|ExpandDataFileName)\W" \
        --dataicon "paper-clip.gif" \
        --dirmatch "^Testing$" \
        --label "Tests" \
        --link "$CVSWEB_CHECKOUT" \
        --linksuffix "$CVSWEB_SUFFIX" \
        --project "$PROJECT_NAME" \
        --store "doc_""$PROJECT_NAME""_class2tests.dox" \
        --title "Class To Tests" \
        --to "$INTERMEDIATE_DOX_DIR" \
        --unique "t" \
        "$SOURCE_DIR/$REL_PATH_TO_TOP"
fi

# ----------------------------------------------------------------------------
# Retrieve the remote VTK tag file.

if test "x$DOWNLOAD_VTK_TAGFILE" == "xON" ; then
  if test "x$VTK_TAGFILE" != "x" ; then
      if test "x$WGET_PROG" != "xNOTFOUND" ; then
          "$WGET_PROG" -nd -nH \
              "$VTK_TAGFILE_REMOTE_DIR/$VTK_TAGFILE" \
              -O "$VTK_TAGFILE_DEST_DIR/$VTK_TAGFILE"
      fi        
  fi
fi

# ----------------------------------------------------------------------------
# Create the Doxygen doc.

if test "x$DOXYGEN_PROG" != "xNOTFOUND" ; then

    if test "x$RM_PROG" != "xNOTFOUND" ; then
        "$RM_PROG" -fr "$OUTPUT_DIRECTORY"
    fi

    "$DOXYGEN_PROG" "$DOXYFILE"
fi

# ----------------------------------------------------------------------------
# Clean the HTML pages to remove the path to the intermediate Doxygen dir.

if test "x$PERL_PROG" != "xNOTFOUND" ; then
    "$PERL_PROG" "$PATH_TO_VTK_DOX_SCRIPTS/doc_rmpath.pl" \
        --to "$INTERMEDIATE_DOX_DIR" \
        --html "$OUTPUT_DIRECTORY/html"
fi

# ----------------------------------------------------------------------------
# clean the HTML pages to remove layout pbs

if test "x$PERL_PROG" != "xNOTFOUND" ; then
    "$PERL_PROG" "$PATH_TO_VTK_DOX_SCRIPTS/doc_cleanhtml.pl" \
        --html "$OUTPUT_DIRECTORY/html"
fi

# ----------------------------------------------------------------------------
# Create the CHM HTML HELP doc.

if test "x$COMPILE_HTML_HELP" == "xON" ; then
    if test "x$RESULTING_HTML_HELP_FILE" != "x" ; then
        cd "$OUTPUT_DIRECTORY/html"
        if test "x$HHC_PROG" != "xNOTFOUND" ; then
            "$HHC_PROG" index.hhp
            if test "x$MV_PROG" != "xNOTFOUND" ; then
                "$MV_PROG" -f index.chm "$RESULTING_HTML_HELP_FILE"
            fi
       fi
   fi
fi

# ----------------------------------------------------------------------------
# Create the compressed tar archive.

if test "x$CREATE_HTML_TARZ_ARCHIVE" == "xON" ; then
    if test "x$RESULTING_HTML_TARZ_ARCHIVE_FILE" != "x" ; then
        cd "$OUTPUT_DIRECTORY"
        if test "x$TAR_PROG" != "xNOTFOUND" ; then
            if test "x$RM_PROG" != "xNOTFOUND" ; then
                "$RM_PROG" -f html.tar
            fi
            "$TAR_PROG" -cf html.tar html
            if test "x$GZIP_PROG" != "xNOTFOUND" ; then
                if test "x$RM_PROG" != "xNOTFOUND" ; then
                    "$RM_PROG" -f html.tar.gz
                fi
                "$GZIP_PROG" html.tar
                "$MV_PROG" -f html.tar.gz "$RESULTING_HTML_TARZ_ARCHIVE_FILE"
            fi
       fi
   fi
fi

# ----------------------------------------------------------------------------
# Clean-up.

if test "x$RM_PROG" != "xNOTFOUND" ; then
    "$RM_PROG" -fr "$INTERMEDIATE_DOX_DIR"

    if test "x$DOWNLOAD_VTK_TAGFILE" == "xON" ; then
        if test "x$VTK_TAGFILE" != "x" ; then
            "$RM_PROG" -f "$VTK_TAGFILE_DEST_DIR/$VTK_TAGFILE"
        fi
    fi

    if test "x$COMPILE_HTML_HELP" == "xON" ; then
        if test "x$RESULTING_HTML_HELP_FILE" != "x" ; then
            if test "x$ALLOW_ERASE_OUTPUT_DIRECTORY" == "xON" ; then
                "$RM_PROG" -fr "$OUTPUT_DIRECTORY"
            fi
        fi
    fi
fi
